unit Menu;

interface

uses
  Classes, SysUtils, Controls,
  RaApplication, RaBase, RaControlsVCL, jpeg, DataModule, Units, Graphics,
  ErrorMessage, ReportPrepare;

type

  TMode = (GuestMode, UserMode);

  TfrmMenu = class(TRaFormCompatible)
    btnUnits: TRaBitButton;
    btnLogout: TRaBitButton;
    IntegratorLogo: TRaImage;
    btnAccountManager: TRaBitButton;
    RaPicturePublisher1: TRaPicturePublisher;
    btnStat: TRaBitButton;
    procedure btnLogoutClick(Sender: TObject);
    procedure btnUnitsClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnAccountManagerClick(Sender: TObject);
    procedure btnStatClick(Sender: TObject);
  private
    procedure ShowInGuestMode;
    procedure ShowInUserMode;
  public
    fMode: TMode;
    
  end;

var
  frmMenu: TfrmMenu;

implementation

uses
  Login, AccountsManager;

{$R *.dfm}

procedure TfrmMenu.btnAccountManagerClick(Sender: TObject);
begin
  frmAccounts.Show;
end;

procedure TfrmMenu.btnLogoutClick(Sender: TObject);
begin
  Self.Hide;
  frmLogin.Show;
end;

procedure TfrmMenu.btnStatClick(Sender: TObject);
begin
  frmReportPrepare.Show
end;

procedure TfrmMenu.FormShow(Sender: TObject);
begin
  if fMode = GuestMode then
    ShowInGuestMode
  else
    ShowInUserMode;
end;

procedure TfrmMenu.btnUnitsClick(Sender: TObject);
begin
  frmUnits.Show
end;

procedure TfrmMenu.ShowInGuestMode;
var
  Mediana: integer;
const
  border = 20;
begin
  Mediana := Self.Width div 2;
  btnUnits.Visible := false;
  btnStat.Left := Mediana - btnStat.Width - border div 2;
  btnLogout.Left := Mediana + border div 2;
  btnAccountManager.Visible := false;
end;

procedure TfrmMenu.ShowInUserMode;
var
  Mediana: integer;
const
  border = 20;
begin
  Mediana := Self.Width div 2;
  btnUnits.Visible := true;
  btnUnits.Left := Mediana - btnUnits.Width div 2;
  btnStat.Left := btnUnits.Left - btnStat.Width - border;
  btnLogout.Left := btnUnits.Left + btnUnits.Width + border;
  btnAccountManager.Left := btnLogout.Left;
  btnAccountManager.Visible := true;
end;

end.
